

var pageContext = new PageContextDatatable(settings||{});
pageContext.setting.canShowTrigger = true;
pageContext.setting.canShowVersion = true;
pageContext.formInit = function(layero){
}

pageContext.getOtherOperBtn = function(id,label,record){
	var html = [];	
	if(pageContext.setting.canShowTrigger){
		html.push('<li>');
		html.push('<a href="javacript:void(0)" data-rel="tooltip" label="'+label+'" url="'+window.global.ctx+'/str/table/field/index?tableId='+record.id+'" val="'+id+'" class="tooltip-success propBtn" data-rel="tooltip" title="字段信息">');
		html.push('<span class="green">');
		html.push('<i class="ace-icon fa fa-arrow-right icon-on-right bigger-120"></i>');
		html.push('</span>');
		html.push('</a>');
		html.push('</li>');
	}
	if(pageContext.setting.canShowVersion){
		html.push('<li>');
		html.push('<a href="javacript:void(0)" data-rel="tooltip" label="'+label+'" url="'+window.global.ctx+'/str/table/version/index?tableId='+record.id+'" val="'+id+'" class="tooltip-success versionBtn" data-rel="tooltip" title="版本">');
		html.push('<span class="green">');
		html.push('<i class="ace-icon fa fa-cog bigger-120"></i>');
		html.push('</span>');
		html.push('</a>');
		html.push('</li>');
	}
	return html.join("");
}
pageContext.getOtherPingPuOperBtn = function(id,label,record){
	var html = [];
	if(pageContext.setting.canShowTrigger){
		html.push('<button class="btn btn-xs btn-info propBtn" data-rel="tooltip" label="'+label+'" url="'+window.global.ctx+'/str/table/field/index?tableId='+record.id+'" val="'+id+'" title="字段信息">');
		html.push('<i class="ace-icon fa icon-on-right fa-arrow-right bigger-120"></i>');
		html.push('</button>');
	}
	if(pageContext.setting.canShowVersion){
		html.push('<button class="btn btn-xs btn-pink versionBtn" data-rel="tooltip" label="'+label+'" url="'+window.global.ctx+'/str/table/version/index?tableId='+record.id+'" val="'+id+'" title="版本">');
		html.push('<i class="ace-icon fa fa-cog bigger-120"></i>');
		html.push('</button>');
	}
	return html.join("");
}

pageContext.renderAfterEventOther = function(){
	$('#'+pageContext.setting.tableId+' >tbody').delegate("tr > td .propBtn","click",function(e){
		 var label = $(this).attr("label");
		 var url = ($(this).attr("url"));
		 var action = window.global.getFinalUrl(url);
		 load(action,"page-content",true,"表【"+label+"】字段",function(){
				
		 });
	     return false;
	});
	$('#'+pageContext.setting.tableId+' >tbody').delegate("tr > td .versionBtn","click",function(e){
		 var val = $(this).attr("val");
		 var label = $(this).attr("label");
		 var url = ($(this).attr("url"));
		 var action = window.global.getFinalUrl(url);
		 load(action,"page-content",true,"表【"+label+"】版本",function(){
				
		 });
	     return false;
	});
}
pageContext.exportData = function(me){
	 var val = $(me).attr("val");
	 var label = $(me).attr("label");
	 var url = ($(me).attr("url"));
	 var action = window.global.getFinalUrl(url);
	 $("#newPage").closest("a").attr("href",url);
	 $("#newPage").click();
   return false;
}
pageContext.importData = function(me){
	 var val = $(me).attr("val");
	 var label = $(me).attr("label");
	 var url = ($(me).attr("url"));
	 var action = window.global.getFinalUrl(url);
	 load(action,"page-content",true,label,function(){
			
	 });
   return false;
}
pageContext.toAdd = function(option){
	 var me = $(option.target);
	 var string = me.attr("para-data");
	var action = window.global.getFinalUrl(pageContext.setting.toAddUrl);
 	var pairs = string.split('&'), d = decodeURIComponent, name, value;
	$.each(pairs, function(i, pair) {
		pair = pair.split('=');
		name = d(pair[0]);
		value = d(pair[1]);
		action = window.global.addPara(action,name,value);
	});
	load(action,"page-content",true,"新增"+pageContext.modelName,function(){
		
	});
}
pageContext.toDetail = function(id,data){
	var action = window.global.getFinalUrl(pageContext.setting.toDetailUrl);
	action = window.global.addPara(action,"id",id,true)
	load(action,"page-content",true,pageContext.modelName+"详情",function(){
		
	});
}
pageContext.toUpdate = function(id,data){
	var action = window.global.getFinalUrl(pageContext.setting.toUpdateUrl);
	action = window.global.addPara(action,"id",id,true)
	load(action,"page-content",true,"修改"+pageContext.modelName,function(){
		
	});
}
jQuery(function($) {
   pageContext.init();

	 $(document).find("input").each(function(){
		 $(this).attr("autocomplete","off");
	 });
   var layero = $("#searchForm");
	layero.find('select[novalid!="true"]').each(function(){
		var novalid = $(this).attr("noconvert");
		if(novalid!="true"){
			var $span = layero.find(this).select2({
	            language: "zh-CN"
		            ,matcher:select2Matcher})
	            .next("span")
	            ;
		}
	  });
}); 
